//instanceof : 判断 当前实例 是不是这个类和这个类的父类 的实例
function myInstanceOf(instance, MyClass) {
  // instance的原型链 有没有 MyClass.prototype

  //instance.__proto__.__proto__.__proto__ === MyClass.prototype;
  if (!instance || !MyClass || !instance.__proto__ || !MyClass.prototype) {
    return false;
  }

  let current = Object.create(instance);

  while (current) {
    if (current === MyClass.prototype) {
      return true;
    }

    current = current.__proto__;
  }

  return false;


}


function Parent() {
}

function Child() {
}

// 继承
Child.prototype.__proto__ = Parent.prototype;

const obj = new Child();
console.log(myInstanceOf(obj, Child));   // true
console.log(myInstanceOf(obj, Parent));   // true
console.log(myInstanceOf(obj, Object));   // true
console.log(myInstanceOf(obj, Date));   //false
